package com.gs.weather.service.impl;

import com.github.pagehelper.PageHelper;
import com.gs.weather.dao.DisasterProcessDao;
import com.gs.weather.entity.DisasterProcess;
import com.gs.weather.service.DisasterProcessService;
import com.gs.weather.utils.Constant;
import com.gs.weather.utils.HttpUtils;
import com.gs.weather.vo.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/9/21 0021
 */
@Service
public class DisasterProcessServiceImpl implements DisasterProcessService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    DisasterProcessDao disasterProcessDao;

    @Override
    public Long addProcess(DisasterProcess process) {
        return disasterProcessDao.addDisasterProcess(process);
    }

    @Override
    public ResponseEntity updateProcess(DisasterProcess process) {
        disasterProcessDao.updateDisasterProcess(process);
        return HttpUtils.buildStringResponse("OK", HttpStatus.OK);
    }

    @Override
    public DisasterProcess getProcessById(long id) {
        DisasterProcess processes = disasterProcessDao.queryDisasterProcessById(id);
        return processes;
    }

    @Override
    public PageBean getAllProcess(String name, String time, Integer pageNum) {
        pageNum = pageNum == null?1:pageNum;
        PageHelper.startPage(pageNum, Constant.PAGE_SIZE);
        List<DisasterProcess> processes = disasterProcessDao.queryAllProcessesWithCondition(name,time);
        PageBean<DisasterProcess> result = new PageBean(processes);
        return result;
    }

    @Override
    public ResponseEntity deleteProcess(long id) {
        disasterProcessDao.deleteDisasterProcess(id);
        return HttpUtils.buildStringResponse("OK", HttpStatus.OK);
    }
}
